1
Kỹ thuật Gợi ý (Prompt Engineering): Giao diện chính cho Trí tuệ nhân tạo sinh ra nội dung
AI011Lesson 2
00:00

Cơ bản về Kỹ thuật Gợi ý

Kỹ thuật Gợi ý (PE) là quá trình thiết kế và tối ưu đầu vào văn bản để định hướng các Mô hình Ngôn ngữ lớn (LLM) đến kết quả chất lượng cao, nhất quán.

1. Xác định Giao diện

Là gì: Nó đóng vai trò là giao diện "lập trình" chính cho trí tuệ nhân tạo sinh ra nội dung.
Tại sao: Nó chuyển cuộc tương tác từ việc dự đoán văn bản thô, không thể đoán trước sang việc thực thi các chỉ dẫn có chủ đích, được cấu trúc rõ ràng.

2. Nền tảng Mô hình

  • Mô hình cơ sở LLM: Được huấn luyện đơn giản để dự đoán token tiếp theo dựa trên các mối quan hệ thống kê trong tập dữ liệu khổng lồ, nhằm tối đa hóa xác suất $P(w_t | w_1, w_2, ..., w_{t-1})$.
  • Mô hình đã được điều chỉnh theo chỉ dẫn LLM: Được tinh chỉnh bằng Học tăng cường với Phản hồi của con người (RLHF) để tuân thủ cụ thể các hướng dẫn và hoạt động như một trợ lý hữu ích.

3. Cấu trúc của một Gợi ý Thành công

Làm thế nào: Một gợi ý mạnh thường bao gồm:

  • Chỉ dẫn: Hành động cụ thể cần thực hiện.
  • Nội dung chính: Dữ liệu mục tiêu cần xử lý.
  • Nội dung phụ: Tham số, định dạng hoặc ràng buộc (để giải quyết tính ngẫu nhiên và ảo giác).
Thực tế về Chia nhỏ Văn bản (Tokenization)
Các mô hình không đọc từ; chúng xử lý các token—những đơn vị nhỏ hơn của chuỗi văn bản được dùng để tính toán xác suất thống kê.
prompt_structure.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
Question 1
What is the primary difference between a Base LLM and an Instruction-Tuned LLM?
Base LLMs only process code, while Instruction-Tuned LLMs process natural language.
Instruction-Tuned models are refined through human feedback to follow specific directions, whereas Base LLMs focus on statistical token prediction.
Base LLMs use tokens, but Instruction-Tuned LLMs read whole words at a time.
There is no difference; they are two terms for the exact same architecture.
Question 2
Why is the use of delimiters (like triple backticks or hashes) considered a best practice in prompt engineering?
They reduce the token count, making the API call cheaper.
They force the model to output in JSON format.
To separate instructions from the content the model needs to process, preventing 'separation of concerns' issues.
They increase the model's temperature setting automatically.
Challenge: Tutor AI Constraints
Refining prompts for educational safety.
You are building a tutor-style AI for a startup. The model is currently giving away answers too quickly and sometimes making up facts when it doesn't know the answer.
AI Tutor Interface
Task 1
Implement "Chain-of-thought" prompting in the system message to prevent the AI from giving away answers immediately.
Solution:
Instruct the model to: "Work through the problem step-by-step before providing the final answer. Do not reveal the final answer until the student has attempted the steps."
Task 2
Apply an "out" to prevent fabrications (hallucinations) when the AI doesn't know the answer.
Solution:
Add the explicit instruction: "If you do not know the answer based on the provided text or standard curriculum, state clearly that you do not know."